#ifndef BUFFER_H_
#define BUFFER_H_

template<typename T, size_t limit> class Buffer {
public:
	typedef T* iterator;
	typedef const T* const_iterator;
private:
	T buf[limit];
	size_t length;
	iterator p_end;

public:
	Buffer(size_t _size) :
		length(_size), p_end(buf + length) {
		for (iterator i = buf; i < p_end; ++i)
			*i = 0;
	}

	Buffer(const_iterator start, size_t _size) :
		length(_size), p_end(buf + length) {

		for (iterator i = buf; i < p_end; ++i, ++start)
			*i = *start;
	}

	~Buffer() {
	}

	size_t size() const {
		return length;
	}

	iterator begin() {
		return buf;
	}
	const_iterator begin() const {
		return buf;
	}
	iterator end() {
		return buf + length;
	}
	const_iterator end() const {
		return buf + length;
	}

	friend bool operator==(const Buffer<T, limit>& one,
			const Buffer<T, limit>& other) {
		if (one.length != other.length)
			return false;
		const_iterator i = one.begin();
		const_iterator j = other.begin();
		while (i != one.end() && j != other.end()) {
			if (*i != *j)
				return false;
			++i;
			++j;
		}
		return true;
	}
	friend bool operator!=(const Buffer<T, limit>& one,
			const Buffer<T, limit>& other) {
		return !(one == other);
	}
};

#endif /* BUFFER_H_ */
